/*
* $Id: app_main.c,v 1.21 2008/03/07 01:44:55 sunny Exp $
*/
/*
*******************************************************************************
**  Include files
*******************************************************************************
*/
#include "unet.h"

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	Get node's 64-bit MAC address and store at MAC_ADDRESS[].
**
**  Parameters:
**	None
**
**  Returns:
**	seed number for srand()
**
**-----------------------------------------------------------------------------
*/
UINT16 GetMacAddress(void)
{
	UINT16 seed = 0xbeef;
	UINT8 i;

	for(i = 0; i < sizeof(MAC_ADDRESS); i++) {

	#if 0 // TODO: read from EEPROM / FLASH ROM and store at MAC_ADDRESS[].
	#endif

	        if(seed & 0x8000) {
			seed <<= 1;
			seed |= 1;
		}
	        else {
			seed <<= 1;
		}
		seed ^= MAC_ADDRESS[i];
	}

	return(seed);
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	third stage initialization, called by main() when all resources are initialized.
**	Init. user application (called once)
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void AppInit( void )
{
	UNET_INIT(UNET_PAN_ID, UNET_CHANNEL, 0xffff, UNET_MAX_CHILD, UNET_MAX_ROUTER, UNET_MAX_DEPTH);
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	user application main function (called in an endless loop)
**
**  Parameters:
**	None
**
**  Returns:
**	None
**
**-----------------------------------------------------------------------------
*/
void AppMain( void )
{
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	Unet Rx data handler by user aplication (called when received a UNET data packet)
**
**  Parameters:
**	pointer of UNET packet
**
**  Returns:
**	1: data processed
**      0: data NOT processed (call to default handler)
**
**-----------------------------------------------------------------------------
*/
UINT8 AppProcUnetRxData( UNET_HEADER *MsgPtr, UINT8 Length )
{
	return(0);
}

/*
**-----------------------------------------------------------------------------
**
**  Abstract:
**	UART data handler by user aplication (called when received a UART data packet)
**
**  Parameters:
**	pointer of UART packet
**
**  Returns:
**	1: data processed
**      0: data NOT processed (call to default handler)
**
**-----------------------------------------------------------------------------
*/
UINT8 AppProcUartRxData( UINT8 *MsgPtr, UINT8 Length )
{
	return(0);
}
